gtkplacesview: allow to cancel connection to server
authorCarlos Soriano <csoriano@gnome.org>
Mon, 17 Aug 2015 22:42:23 +0000 (00:42 +0200)
committerCarlos Soriano <csoriano@gnome.org>
Mon, 17 Aug 2015 23:05:20 +0000 (01:05 +0200)
We were not allowing to cancel the operation at all, and at
most the operation was cancelled only when clicked connect again.

Also due to gvfs bug 753735 we actually weren't cancelling
at all, and therefore creating multiple dialogs.

gtk/gtkplacesview.c

index 3721be71bfb7d55e3aad3a822ca237244cc217fc..4ca2f56a349b0ca61eb804b9d452c6a554cb6e3e 100644 (file)
@@ -77,6 +77,7 @@ struct _GtkPlacesViewPrivate
   guint                          should_open_location : 1;
   guint                          should_pulse_entry : 1;
   guint                          entry_pulse_timeout_id;
+  guint                          connecting_to_server : 1;
 };
 
 static void        mount_volume                                  (GtkPlacesView *view,
@@ -912,6 +913,10 @@ server_mount_ready_cb (GObject      *source_file,
   set_busy_cursor (view, FALSE);
 
   g_file_mount_enclosing_volume_finish (location, res, &error);
+  /* Restore from Cancel to Connect */
+  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
+  gtk_widget_set_sensitive (priv->address_entry, TRUE);
+  priv->connecting_to_server = FALSE;
 
   if (error)
     {
@@ -1130,16 +1135,24 @@ mount_server (GtkPlacesView *view,
   GtkWidget *toplevel;
 
   priv = gtk_places_view_get_instance_private (view);
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
-  operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
 
   g_cancellable_cancel (priv->cancellable);
   g_clear_object (&priv->cancellable);
+  /* User cliked when the operation was ongoing, so wanted to cancel it */
+  if (priv->connecting_to_server)
+    return;
+
   priv->cancellable = g_cancellable_new ();
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+  operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
 
   set_busy_cursor (view, TRUE);
   priv->should_pulse_entry = TRUE;
   gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.1);
+  /* Allow to cancel the operation */
+  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Cance_l"));
+  gtk_widget_set_sensitive (priv->address_entry, FALSE);
+  priv->connecting_to_server = TRUE;
 
   if (priv->entry_pulse_timeout_id == 0)
     priv->entry_pulse_timeout_id = g_timeout_add (100, (GSourceFunc) pulse_entry_cb, view);